from datetime import datetime
import hashlib
import random
from loguru import logger

from ..utils.tarot_car_name import tarot_cards

class RandomCardDraw:

    def __init__(self,question:str):
        # 获取当前时间戳
        self.current_timestamp = datetime.now().timestamp()
        self._hash_question = self._hash_question(question)

    @staticmethod
    def _hash_question(question: str) -> str:
        hash_object = hashlib.sha256(question.encode())
        hashed_value = hash_object.hexdigest()
        return hashed_value

    def random_card_draw(self)->list:
        random_seed = str(self.current_timestamp) + self._hash_question
        logger.info(f"random_seed:{random_seed}")
        random.seed(random_seed)

        random_num = random.randint(0, len(tarot_cards) - 1)
        return [tarot_cards[random_num]]

    # TODO:实现从图数据库获取数据



# if __name__ == "__main__":
#     res = RandomCardDraw("你好").random_card_draw()
#     # res = random_card_draw_mod.random_card_draw()
#     print(res)

    